package com.hjm.project.AgentMarketingReward.controller;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import com.hjm.common.utils.StringUtils;
import com.hjm.project.agentInfo.agentInfo.domain.AgentInfo;
import com.hjm.project.agentInfo.agentInfo.service.IAgentInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.AgentMarketingReward.domain.AgentMarketingReward;
import com.hjm.project.AgentMarketingReward.service.IAgentMarketingRewardService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;
import javax.annotation.Resource;

/**
 * 资深总监营销奖励Controller
 * 
 * @author maker-platform
 * @date 2021-04-06
 */
@Controller
@RequestMapping("/AgentMarketingReward/AgentMarketingReward")
public class AgentMarketingRewardController extends BaseController
{
    private String prefix = "AgentMarketingReward";

    @Resource
    private IAgentMarketingRewardService agentMarketingRewardService;

    @Resource
    private IAgentInfoService agentInfoService;

    @RequiresPermissions("AgentMarketingReward:AgentMarketingReward:view")
    @GetMapping()
    public String AgentMarketingReward()
    {
        return prefix + "/AgentMarketingReward";
    }


    /**
     * 获取所有上级为 100000000的代理 (资深总监-V9)
     * @Param []
     * @Return java.lang.String
     */
    @GetMapping("/selectAgentInfoList")
    public String selectAgentInfoList()
    {
        return prefix + "/selectAgentInfoList";
    }


    /**
     * 前往新增奖励页面
     * @Param []
     * @Return java.lang.String
     */
    @GetMapping("/rewardAdd")
    public String rewardAdd()
    {
        return prefix + "/rewardAdd";
    }
    /**
     * 获取某个代理的本级级以下
     * @Param []
     * @Return java.lang.String
     */
    @GetMapping("/selectAgentInfoRecursive")
    public String selectAgentInfoRecursive(@RequestParam Map params,ModelMap mmp)
    {
        mmp.put("agentNum",params.get("agentNum"));
        return prefix + "/selectAgentInfoRecursive";
    }


    /**
     * 获取所有上级为 100000000的代理 (资深总监-V9)
     * @Param []
     * @Return java.lang.String
     */
    @PostMapping("/selectAgentInfoListData")
    @ResponseBody
    public TableDataInfo selectAgentInfoListData(AgentInfo agentInfo) {
        startPage();
        List<AgentInfo> list = agentInfoService.selectAgentInfoList(agentInfo);
        return getDataTable(list);
    }


    /**
     * 获取某个代理的本级级以下
     * @Param []
     * @Return java.lang.String
     */
    @PostMapping("/selectAgentInfoRecursiveData")
    @ResponseBody
    public TableDataInfo selectAgentInfoRecursiveData(AgentInfo agentInfo)
    {
        startPage();
        List<AgentInfo> list = agentInfoService.selectBetweenAgentNoBelongAgent(agentInfo);
        return getDataTable(list);
    }






    /**
     * 查询资深总监营销奖励列表
     */
    @RequiresPermissions("AgentMarketingReward:AgentMarketingReward:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentMarketingReward agentMarketingReward)
    {
        startPage();
        List<AgentMarketingReward> list = agentMarketingRewardService.selectAgentMarketingRewardList(agentMarketingReward);
        return getDataTable(list);
    }

    /**
     * 导出资深总监营销奖励列表
     */
    @RequiresPermissions("AgentMarketingReward:AgentMarketingReward:export")
    @Log(title = "资深总监营销奖励", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentMarketingReward agentMarketingReward)
    {
        List<AgentMarketingReward> list = agentMarketingRewardService.selectAgentMarketingRewardList(agentMarketingReward);
        ExcelUtil<AgentMarketingReward> util = new ExcelUtil<AgentMarketingReward>(AgentMarketingReward.class);
        return util.exportExcel(list, "AgentMarketingReward");
    }

    /**
     * 新增资深总监营销奖励
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存资深总监营销奖励
     */
    @RequiresPermissions("AgentMarketingReward:AgentMarketingReward:add")
    @Log(title = "资深总监营销奖励", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentMarketingReward agentMarketingReward)
    {
        return toAjax(agentMarketingRewardService.insertAgentMarketingReward(agentMarketingReward));
    }

    /**
     * 修改资深总监营销奖励
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        AgentMarketingReward agentMarketingReward = agentMarketingRewardService.selectAgentMarketingRewardById(id);
        mmap.put("agentMarketingReward", agentMarketingReward);
        return prefix + "/edit";
    }

    /**
     * 修改保存资深总监营销奖励
     */
    @RequiresPermissions("AgentMarketingReward:AgentMarketingReward:edit")
    @Log(title = "资深总监营销奖励", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentMarketingReward agentMarketingReward)
    {
        return toAjax(agentMarketingRewardService.updateAgentMarketingReward(agentMarketingReward));
    }

    /**
     * 删除资深总监营销奖励
     */
    @RequiresPermissions("AgentMarketingReward:AgentMarketingReward:remove")
    @Log(title = "资深总监营销奖励", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(agentMarketingRewardService.deleteAgentMarketingRewardByIds(ids));
    }



    /**
     * 添加达标返现奖励数据
     */
    @RequiresPermissions("AgentMarketingReward:AgentMarketingReward:add")
    @Log(title = "达标返现奖励数据", businessType = BusinessType.DELETE)
    @PostMapping( "/addReward")
    @ResponseBody
    public AjaxResult addReward(AgentMarketingReward marketingReward) throws ParseException {
        //必填信息
        //到期时间
        if (StringUtils.isEmpty(marketingReward.getEndDate())) {
            return error("请选择到期时间");
        }
        //营销奖励
        if (StringUtils.isEmpty(marketingReward.getFxEight()) && StringUtils.isEmpty(marketingReward.getFxYsf())) {
            return error("请选择营销奖励");
        }
        return toAjax(agentMarketingRewardService.addReward(marketingReward));
    }






}
